<?php
namespace app\index\controller;

use app\admin\controller\Order;
use app\common\entity\Mywallet;
use app\common\entity\MywalletLog;
use app\common\entity\User;
use app\common\entity\UserInviteCode;
use app\common\service\Users\Service;
use app\common\shop\AddressModel;
use app\common\shop\CartModel;
use app\common\shop\ConfigModel;
use app\common\shop\OrderGoodsModel;
use app\common\shop\OrderModel;
use app\common\shop\ShopGoodsModel;
use app\common\shop\ShopGroupModel;
use app\common\shop\SpecListModel;
use think\Db;
use think\Request;
use think\Controller;
class Shoporder extends Base {
    /**
     * [立即购买]
     * @param
     * @return
     */
    public function addOrder( Request $request ){

        $uid = $this->userId;
        $cartData = $request->post('cartid');// 购物车
        $goods = [];
        $total = 0;
        $allnumber = 0;
        if($cartData){// 购物车
            $data = explode(',', $cartData);// 购物车信息参数：1-2,2-3[购物车id-数量,购物车id-数量]

            foreach ($data as $key => $value) {
                $cart_cid_number = explode('-', $value);
                $cart = CartModel::getCartIdInfo($cart_cid_number[0]);
                if($cart_cid_number[0] != 0){
                    $speclist_data = SpecListModel::getInfo($cart['speclistid']);// 规格信息
                    if(empty($speclist_data)) return json(['code'=>1,'msg'=>'规格已不存在']);
                }
                // 购物车商品
                $cart_goods = CartModel::getCartGoods($cart);
                if($cart_goods['status'] ==0) return json(['code'=>1,'msg'=>'有商品已经下架']);
                // 购买数量
                $cart_goods['number'] = $cart_cid_number[1];
                if($cart_goods['total'] < $cart_cid_number[1]) return json(['code'=>1,'msg'=>'商品库存不足']);
                //@todo 普通商品只能单独购买
                if(($cart_goods['shoptype'] == 1 || $cart_goods['shoptype'] == 4) &&(count($data) > 1 || $cart_goods['number'] > 1)){
                    return json(['code'=>1,'msg'=>'普通商品只能单独购买']);
                }
                // 小计
                $cart_goods['allmoney'] = $cart_goods['price'] * $cart_goods['number'];
                // 总计
                $total += $cart_goods['allmoney'];
                $allnumber += $cart_goods['number'];
                array_push($goods, $cart_goods);
            }
        }else{
            $goodsid = $request->post('goodsid');
            if(empty($goodsid)) return json(['code' => 1, 'msg' => '请选择商品']);
            $speclistid = $request->post('speclistid');
            $number = $request->post('number',1);
            $isgroup = $request->post('isgroup',0);// 是否拼团 1是 0否
            if($speclistid != 0){
                $speclist_data = SpecListModel::getInfo($speclistid);// 规格信息
                if(empty($speclist_data)) return json(['code'=>1,'msg'=>'规格已不存在']);
            }
            $goodsdata = CartModel::getCartGoods(['goodsid'=>$goodsid,'speclistid'=>$speclistid]);

            if($goodsdata['status'] == 0) return json(['code'=>1,'msg'=>'商品已经下架']);
            if($number > $goodsdata['total']) return json(['code'=>1,'msg'=>'商品库存不足']);
            /*2021-1-5改*/
            if($isgroup==1){
                // 拼团商品-拼团中
                $goodsdata['price'] = $goodsdata['team_prices'];
            }
            /*end*/

            $goodsdata['number'] = $number;// 数量
            //@todo 普通商品只能单独购买
            if(($goodsdata['shoptype'] == 1 || $goodsdata['shoptype'] == 4) && $goodsdata['number'] > 1){
                return json(['code'=>1,'msg'=>'普通商品只能单独购买']);
            }
            $goodsdata['allmoney'] = $number*$goodsdata['price'] ;// 小计
            $total += $goodsdata['price'] *$number;// 总价
            $allnumber += $number;
            array_push($goods, $goodsdata);
        }
        // 检查是否有不同类型的商品-普通商品、团购商品、代金券商品、代金券
        $checkGoodsType = ShopGoodsModel::checkGoodsType($goods);
        if(!$checkGoodsType) return json(['code'=>1,'msg'=>'不能购买两个不同类型的商品']);
        $list['goods'] = $goods;
        $list['allmoney'] = $total;
        $list['allnumber'] = $allnumber;

        return json(['code'=>0,'msg'=>'请求成功','info'=>$list]);

    }

    /**
     * [提交订单]
     * @return
     */
    public function commitOrder(Request $request){

        $uid = $this->userId;
        $orderid = $request->post('orderid');// 重复提交
        $addressid = $request->post('addressid');// 地址id
        $address = AddressModel::getInfo($addressid,$uid);
        if(empty($address)) return json(['code'=>1,'msg'=>'地址不存在']);
        // 是否拼团
        $isgroup = $request->post('isgroup',0);
        $address = $address->toArray();
        // 商品信息：商品id-商品规格id-数量，多商品使用分号隔开
        $goods_data = $request->post('goods_data');
        if(empty($goods_data)) return json(['code'=>1,'msg'=>'参数错误']);
        $data_list = explode(';', $goods_data);// 分割
        $order_goods = [];// 商品订单信息
        $getOrdersn = OrderModel::getOrdersn();
        $total = 0;// 订单总价
        $credit = 0;// 订单总价
        $groupid = $request->post('groupid',0);
        if($groupid == 0){
            $isgroup == 1;
        }

        foreach ($data_list as $key => $value) {
            $goods_list = explode('-', $value);
            // 没有传id 或者 数量
            if(!isset($goods_list[0]) || !isset($goods_list[2])) return json(['code'=>1,'msg'=>'参数错误']);
            $goodsid = $goods_list[0];// 商品id
            $spec_list_id = $goods_list[1]??0;//规格id
            $goods_number = $goods_list[2];//数量
            if(!is_numeric($goodsid) || !is_numeric($spec_list_id) || !is_numeric($goods_number) ){
                return json(['code' => 1, 'msg' => '参数错误']);
            }
            $goodsData = [
                'goodsid'=>$goods_list[0],
                'speclistid'=>$goods_list[1],
                'number'=>$goods_list[2],
            ];
            if($goodsData['speclistid'] != 0){
                $speclist_data = SpecListModel::getInfo($goodsData['speclistid']);// 规格信息
                if(empty($speclist_data)) return json(['code'=>1,'msg'=>'规格已不存在']);
            }
            $goods = ShopGoodsModel::getSpecGoods($goodsData);// 商品信息

            if(empty($goods) || $goods['status'] == 0) return json(['code'=>1,'msg'=>'商品已删除或已下架']);

            // 库存是否足够
            if($goods['total'] < $goodsData['number']) return json(['code'=>1,'msg'=>$goods['title'].'库存不足']);
            if($isgroup==1){
                $goods['price'] = $goods['team_prices'];
            }
            //@todo 普通商品只能单独购买
            if(($goods['shoptype'] == 1 || $goods['shoptype'] == 4) &&(count($data_list) > 1 || $goodsData['number'] > 1)){
                return json(['code'=>1,'msg'=>'普通商品只能单独购买']);
            }
            $alltotal = bcmul($goods_number , $goods['price'] ,2);
            $og = [
                'uid'=>$uid,
                'ordersn'=>$getOrdersn,
                'goodsid'=>$goodsid,
                'specid'=>$spec_list_id,
                'number'=>$goods_number,
                'price'=>$goods['price'],
                'alltotal'=> $alltotal,
                'shoptype'=>$goods['shoptype'],
                'spectitle'=>$goods['spec_title']??'',
            ];
            array_push($order_goods,$og);
            $total += $alltotal;
            $credit += $goods['credit'];// 积分
            $shoptype = $goods['shoptype'];
            $goodsid = $goods['id'];// 拼团商品id
            // 拼团需要人数
            $number = $goods['groupnumber'];
        }

        // 检查是否有不同类型的商品-普通商品、团购商品、代金券商品、代金券
        $checkGoodsType = ShopGoodsModel::checkGoodsType($order_goods);
        if(!$checkGoodsType) return json(['code'=>1,'msg'=>'不能购买两个不同类型的商品']);
        $groupid = $request->post('groupid',0);

        //        if($isgroup == 0){
        //            $groupid == 0;
        //        }
        //        if($groupid == 0){
        //            $isgroup == 1;
        //        }
        // 订单信息
        $order_data = [
            'uid'=>$uid,
            'total'=>$total,
//            'paytype'=>$paytype,
            'ordersn'=>$getOrdersn,
            'content'=>$request->post('content'),// 留言
            'addressid'=>$addressid,
            'shoptype'=>$shoptype,
            'address_date'=>serialize($address),
            'groupid'=>$groupid,
            'credit'=>$credit,
            'isgroup'=>$isgroup,
        ];
        $playgame = 0;
        // 拼团和代金券商城不能玩游戏
        if($shoptype == 2 || $shoptype == 3){
            $order_data['playgame'] = 1;// 不可以玩游戏
            $playgame = 1;
        }
        // 是否自己拼自己-不能自己拼自己的订单
        if($groupid && empty($orderid)){
            $group = ShopGroupModel::getInfo($groupid);
            if($group['uid'] == $uid){
                return json(['code' => 1, 'msg' => '不能拼自己的订单']);
            }
        }
        Db::startTrans();
        try{
            $orders = '';
            if($orderid){
                $orders = OrderModel::getInfo($orderid);
            }
            if($orders){
                OrderModel::edit($order_data,$orderid);
                foreach ($order_goods as $key => $value) {
                    $value['orderid'] = $orderid;
                    $order_goods = OrderGoodsModel::where(['orderid'=>$orderid,'goodsid'=>$value['goodsid'],'specid'=>$value['specid']])->find();
                    OrderGoodsModel::edit($value,$order_goods['id']);
                }
            }else{

                // 拼团商品-添加拼团记录 自己开团
                if($shoptype == 3 && empty($groupid) ){
                    // && $isgroup == 1
                    // 删除未付款拼团
                    ShopGroupModel::where('uid',$uid)->where('goodsid',$goodsid)->where('status',-1)->delete();
                    if($isgroup==1){
                        $gid = ShopGroupModel::add(['uid'=>$uid,'number'=>$number,'goodsid'=>$goodsid,'overtime'=>ShopGroupModel::getOvertime(),'status'=>'-1','havenumber'=>0]);
                    }else{
                        $gid = ShopGroupModel::add(['uid'=>$uid,'number'=>1,'goodsid'=>$goodsid,'overtime'=>ShopGroupModel::getOvertime(),'status'=>'-1','havenumber'=>0]);
                    }
                    $order_data['groupid'] = $gid;
                }

                $orderid = OrderModel::add($order_data);
                foreach ($order_goods as $key => $value) {
                    $value['orderid'] = $orderid;
                    OrderGoodsModel::add($value);
                }
            }
            // 支付方式
            $getPaytype = OrderModel::getPaytype($shoptype,$total,$uid);
            Db::commit();
            return json(['code'=>0,'msg'=>'下单成功','info'=>['ordersn'=>$getOrdersn,'orderid'=>$orderid,'total'=>$total,'shoptype'=>$shoptype,'playgame'=>$playgame,'getPaytype'=>$getPaytype]]);
        } catch (Exception $e) {
            Db::rollback();
            return json(['code' => '1', 'msg' => '系统错误,请联系技术人员处理']);
        }
    }
    /**
     * [支付订单]
     * @return
     */
    public function payOrder(Request $request){
        $uid = $this->userId;
        $orderid = $request->post('orderid',7);

        $order = OrderModel::getInfo($orderid);
        if(empty($order)) return json(['code'=>1,'msg'=>'订单不存在，请重新下单']);
        if($order['status'] != 0 ) return json(['code'=>1,'msg'=>'请勿重复付款']);
        //$user = User::where('id',$uid)->find();

        $paytype = $request->post('paytype',4);// 支付方式
        if(!array_key_exists($paytype,(new OrderModel)->pay )){
            return json(['code'=>1,'msg'=>'支付方式不存在']);
        }
        if($paytype != 3 && $paytype != 4 && $paytype != 5){
            return json(['code'=>1,'msg'=>'支付方式错误']);
        }

        Db::startTrans();
        try{

            if( $paytype == 3 ){// 代金券支付
                $field = 'coupon';
                $fieldType = '2';
                $blessnumber = 0;
                if($order['shoptype'] != 2){
                    // 只有代金券商城能使用代金券
                    return json(['code'=>1,'msg'=>'只有代金券商城能使用代金券']) ;
                }
            }elseif( $paytype == 4){// 福币支付
                $field = 'bless';
                $fieldType = '1';
                $blessnumber = $order['total'];
                if($order['shoptype'] == 2){
                    // 只有代金券商城能使用代金券
                    return json(['code'=>1,'msg'=>'代金券商城不能使用福币']) ;
                }
            }elseif(  $paytype == 5){
                $field = 'money';
                $fieldType = '4';
                $blessnumber = 0;
                if($order['shoptype'] == 2){
                    // 只有代金券商城能使用代金券
                    return json(['code'=>1,'msg'=>'代金券商城不能使用余额']) ;
                }
            }



            //$uid, $number, $wallet_type, $remark, $types, $status
            // $remark = '订单号：'.$order['ordersn'];
            $remark = '购买商品';
            if($order['shoptype'] == 2){
                $remark = '购买代金券商品';
            }
            $money = $order['total'];
            /*if($order['shoptype'] == 4){
                MywalletLog::addLog($order['uid'], $order['total'], 2, $remark, 2, 1);
            }else if($fieldType == 4){
                $checkbalance = (new MyWallet())->checkbalance($uid,$order['total'],'bless');
                if($checkbalance){
                    // 福币已经足够付款
                    $inslog = MywalletLog::addLog($uid, $order['total'], 1 , $remark, 2, 2);
                }else{
                    $blessnumber = (new Mywallet())->balance($uid,'bless');
                    $money = $order['total'] - $blessnumber;// 扣除抵消的部分，剩余需要付款的金额
                    if($money > 0){
                        // 最后再扣福币
                        $checkbalance = (new Mywallet())->checkbalance($uid,$money,$field);
                        // 余额支付
                        if(!$checkbalance) return json(['code'=>1,'msg'=>'余额不足']);
                        // 扣款
                        $inslog = MywalletLog::addLog($uid, $money, $fieldType, $remark, 2, 2);
                    }
                    if($blessnumber>0){
                        $inslog =MywalletLog::addLog($uid,$blessnumber, 1 , $remark, 2, 2);
                        // 抵扣金额
                        OrderModel::where('id',$order['id'])->setField('blessnumber',$blessnumber);
                    }
                }
            }else{
                $blessnumber = (new Mywallet())->balance($uid,$field);
                if($blessnumber < $order['total']){
                    return json(['code'=>1,'msg'=>'余额不足']);
                }
                $inslog = MywalletLog::addLog($uid, $order['total'], $fieldType, $remark, 2, 2);
            }*/

            // 2021-1-10 改
            $blessnumber = (new Mywallet())->balance($uid,$field);
            if($blessnumber < $order['total']){
                return json(['code'=>1,'msg'=>'余额不足']);
            }
            $inslog = MywalletLog::addLog($uid, $order['total'], $fieldType, $remark, 2, 2);
            // end


            /*如果是代金券商品，直接完成订单-得到代金券*/
            if($order['shoptype'] == 4){
                // $allmoney = $order['total']+$order['blessnumber'];
                // MywalletLog::addLog($order['uid'], $allmoney, 2 , '购买代金券', 2, 1);
                //OrderModel::taskOrder($order['id']);// 完成订单
            }
            // 修改订单
            OrderModel::payOrder($order['id'],$paytype,$blessnumber,$order);

            Db::commit();
            return json(['code' => '0', 'msg' => '付款成功','info'=>$order['ordersn']]);
        } catch (\Exception $e) {
            Db::rollback();
            return json(['code' => '1', 'msg' => '系统错误,请联系技术人员处理']);
        }
    }

    /**
     * [微信支付宝支付]
     * @param
     * @return
     */
    public function payWxZfb( Request $request ){
        $uid = $this->userId;
        $orderid = $request->post('orderid');

        $order = OrderModel::getInfo($orderid);
        if(empty($order)) return json(['code'=>1,'msg'=>'订单不存在，请重新下单']);
        if($order['status'] != 0 ) return json(['code'=>1,'msg'=>'请勿重复付款']);
        $paytype = $request->post('paytype');// 支付方式
        if(!array_key_exists($paytype,(new OrderModel)->pay )){
            return json(['code'=>1,'msg'=>'支付方式不存在']);
        }
        $money = $order['total'];
        /*if($order['shoptype'] == 1 ||$order['shoptype'] == 3 ){
            $remark = '订单号：'.$order['ordersn'];
            // 普通商品/团购商品-优先使用福币付款
            // 福币余额支付
            $checkbalance = (new MyWallet())->checkbalance($uid,$order['total'],'bless');
            if($checkbalance >= $order['total']){
                // 福币已经足够付款
                $inslog = MywalletLog::addLog($uid, $order['total'], 1 , $remark, 2, 2);
                // 修改订单-付款完成
                OrderModel::payOrder($order['id'],$paytype, $order['total'],$order);
                $money = 0;
            }else{
                $money = $order['total'] - $checkbalance;// 扣除抵消的部分，剩余需要付款的金额
                if($checkbalance>0){
                    MywalletLog::addLog($uid, $order['total'], 1 , $remark, 2, 2);
                    // 抵扣金额
                    OrderModel::where('id',$order['id'])->setField('blessnumber',$checkbalance);
                }
                // 添加等待金额
                //OrderModel::where('id',$order['id'])->setField('blesswait',$checkbalance);
            }
        }*/
        return json(['code'=>0,'msg'=>'请求成功','info'=>['money'=>$money,'ordersn'=>$order['ordersn'],'order'=>$order]]);
    }

    /**
     * [订单列表]
     * @param
     * @return
     */
    public function orderList( Request $request ){
        $uid = $this->userId;
        $page = $request->post('page');
        $limit = $request->post('limit');
        $where = [];
        $status = $request->post('status');
        if($status != ''){
            $where['status'] = $status;
        }
        if($group = $request->post('group')){
           // $where['shoptype'] = 3;
            $groupfield = ' shoptype = 3';
        }else{
            //$where['shoptype'] = ['<>',3];
            $groupfield = ' shoptype <> 3';
        }
        if($groupstatus = $request->post('groupstatus')){
            // 拼团中
            $where['groupstatus'] = $request->post('groupstatus');
        }
        $where['uid'] = $uid;

        $list =	 OrderModel::where($where)
            ->where($groupfield)
            ->page($page,$limit)
            ->order('createtime desc')
            ->select()->toArray();

        foreach ($list as $key => $value) {
            $goods = OrderGoodsModel::getOrderGoods($value);
            $list[$key]['goods'] = $goods;

            //$list[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
        }

        return json(['code'=>0,'msg'=>'请求成功','info'=>$list]);
    }
    /**
     * [订单详情]
     * @return
     */
    public function orderDetail(Request $request){
        $uid = $this->userId;
        $orderid = $request->post('orderid',2);
        $order = OrderModel::getInfo($orderid)->toArray();
        if(empty($order)) return json(['code'=>1,'msg'=>'订单错误']);
        $order['goods'] = OrderGoodsModel::getOrderGoods($order);

        $order['address_date'] = unserialize($order['address_date']);
        $order['createtime'] = date('Y-m-d H:i:s',$order['createtime']);
        if($order['paytime'] > 0){
            $order['paytime'] = date('Y-m-d H:i:s',$order['paytime']);
        }else{
            $order['paytime'] = '未付款';
        }
        if($order['sendtime'] > 0){
            $order['sendtime'] = date('Y-m-d H:i:s',$order['sendtime']);
        }else{
            $order['sendtime'] = '未发货';
        }
        $order['allmoney'] = $order['total'];
        // 支付方式
        $getPaytype = OrderModel::getPaytype($order['shoptype'],$order['total'],$uid);
        $order['getpaytype'] = $getPaytype;
        return json(['code'=>0,'msg'=>'请求成功','info'=>$order]);
    }
    /**
     * [取消订单]
     * @param
     * @return
     */
    public function cancelOrder( Request $request ){
        $uid = $this->userId;
        $orderid = $request->post('orderid');
        $order = OrderModel::getInfo($orderid);
        if(empty($order)) return json(['code'=>1,'msg'=>'订单错误']);

        if($order['status'] != 0 && $order['status'] != 1 ) return json(['code'=>1,'msg'=>'该订单不能取消']);

        OrderModel::where('id',$orderid)->update(['finishtime'=>time(),'status'=>4]);
        /*if($order['blessnumber'] >0){
            // 存在抵扣福币
            $remark = '订单号：'.$order['ordersn'];
            MywalletLog::addLog($uid, $order['total'], 1 , $remark, 3, 1);
        }*/
        if($order['status'] > 0 ){
            // 付款了，取消订单-返回金钱
            /*1=>'微信支付',
        2=>'支付宝支付',
        3=>'代金券支付',
        4=>'福币支付',
        5=>'余额支付',*/
            $remark = '退款商品';
            if($order['paytype'] == 3){
                //$remark = '订单号：'.$order['ordersn'];
                /*1 => '福币',
                2 => '代金券',
                3 => '福卡',
                4 => '余额',
                5 => '积分',*/
                MywalletLog::addLog($uid, $order['total'], 2 , $remark, 3, 1);
            }elseif($order['paytype'] == 4){
                MywalletLog::addLog($uid, $order['total'], 1 , $remark, 3, 1);
            }elseif($order['paytype'] == 5){
                MywalletLog::addLog($uid, $order['total'], 4 , $remark, 3, 1);
            }else{
                MywalletLog::addLog($uid, $order['total'], 1 , $remark, 3, 1);
            }
        }
        if($order['shoptype'] == 3){
            // 拼团商品-人数减一
            ShopGroupModel::addNumber($order['groupid'],'-1');
        }
        return json(['code'=>0,'msg'=>'取消成功']);
    }

    /**
     * [确认收货]
     * @param
     * @return
     */
    public function confirmOrder( Request $request ){
        $uid = $this->userId;
        $orderid = $request->post('orderid');
        $order = OrderModel::getInfo($orderid);
        if(empty($order)) return json(['code'=>1,'msg'=>'订单错误']);
        if(!$order['expressname'] || !$order['expressnumber']){
            return json(['code'=>1,'msg'=>'未填写发货信息，不能收货']);
        }
        if($order['status'] != 2) return json(['code'=>1,'msg'=>'该订单不能收货']);
        OrderModel::taskOrder($order['id']);
        return json(['code'=>0,'msg'=>'收货成功']);
    }
    /**
     * [验证交易密码]
     * @param
     * @return
     */
    public function checkPass( Request $request ){

        $uid = $this->userId;
        $user = User::where('id',$uid)->find();
        $pay_password = $request->post('pass');
        // 密码
        if(!( (new Service())->checkPayPassword($pay_password,$user)) ) return json(['code'=>1,'msg'=>'密码不正确']);
        return json(['code'=>0,'msg'=>'密码正确']);
    }

    /**
     * [拼团订单详情]
     * @param
     * @return
     */
    public function groupOrderDetail( Request $request ){
        $uid = $this->userId;
        $orderid = $request->post('orderid',7);
        $order = OrderModel::getInfo($orderid);
        if(empty($order)) return json(['code' => 1, 'msg' => '订单不存在']);
        if($order['shoptype'] != 3 && empty($order['groupid']))  return json(['code' => 1, 'msg' => '不是拼团']);
        $shopGroup = ShopGroupModel::getInfo($order['groupid'])->toArray();
        $overtime = $shopGroup['overtime'] - time();
        $finishtime = $shopGroup['overtime'];
        if($overtime <=0 || $shopGroup['status'] == 1){
            // 是否已经完成拼团
            ShopGroupModel::checkOver($order['groupid']);
            // $shopGroup = ShopGroupModel::getInfo($order['groupid'])->toArray();
            $overtime = 0;// 拼团已完成
        }
        $need = $shopGroup['number'] - $shopGroup['havenumber'];
        $goods = OrderGoodsModel::getOrderGoods($order);
        $team = OrderModel::alias('o')
                ->field('o.id,o.uid,u.avatar')
                ->leftJoin('user u','u.id = o.uid')
                ->where('o.groupid',$order['groupid'])
                ->order('createtime asc')
                ->select()->toArray();
        $colonel = User::where('id',$shopGroup['uid'])->field('id,avatar,nick_name')->find()->toArray();
        $colonel['time'] = date('Y-m-d H:i',$shopGroup['createtime']); //下单时间

        $inviteCode = new UserInviteCode();
        $invite_code = $inviteCode->getCodeByUserId($uid);
        $url = $request->domain().'/dist/#/ProductDetails?shoptype=3&goodsid='.$shopGroup['goodsid'].'&invite_code='.$invite_code.'&groupid='.$order['groupid'];
        $iscanbuy =1;// 是否可以购买 0不可以 1可以
        $teamuid = array_column($team,'uid');

        if(in_array($uid,$teamuid)){
            $iscanbuy = 0;// 不可以购买
        }
        if($need>0 && $overtime!=0){
            for ($i=0;$i<$need;$i++){
                $team[]=[];
            }
        }
        $list = [
            'goods'=>$goods,
            'team'=>$team,
            'need'=>$need,
            'overtime'=>$overtime,
            'finishtime'=>$finishtime,
            'colonel'=>$colonel,
            'url'=>$url,
            'groupid'=>$order['groupid'],
            'status'=>$shopGroup['status'],
            //'uid'=>$uid,
            //'teamuid'=>$shopGroup['uid'],
            'iscanbuy'=>$iscanbuy,
        ];
        return json(['code' => 0, 'msg'=>'请求成功','info'=>$list]);
    }
}